package com.dgshanger.sanhxiaofeisc.mvp.presenter

import android.text.TextUtils
import com.dgshanger.sanhxiaofeisc.App.Companion.application
import com.dgshanger.sanhxiaofeisc.R
import com.dgshanger.sanhxiaofeisc.mvp.contract.EditPasswordContract
import com.dgshanger.sanhxiaofeisc.mvp.model.EditPasswordModel
import com.xx.baseuilibrary.mvp.BaseRxMvpPresenter
import com.xx.baseutilslibrary.network.rx.RxHttpObserver

/**
 * EditPasswordPresenter
 * 沉迷学习不能自拔
 * Describe：
 * Created by 雷小星🍀 on 2018/4/28 10:59.
 */

class EditPasswordPresenter : BaseRxMvpPresenter<EditPasswordContract.Model, EditPasswordContract.View>(), EditPasswordContract.Presenter {

    override fun createModel(): EditPasswordContract.Model = EditPasswordModel()

    override fun modifyPwd() {
        val oldPassword = getView()!!.oldPassword
        val newPassword = getView()!!.newPassword
        val surePassword = getView()!!.surePassword

//        if (TextUtils.isEmpty(oldPassword)) {
//            getView()!!.showToast(application.getString(R.string.please_input_old_pw))
//            return
//        }
        if (TextUtils.isEmpty(newPassword)) {
            getView()!!.showToast(application.getString(R.string.please_input_new_pw))
            return
        }
        if (TextUtils.isEmpty(surePassword)) {
            getView()!!.showToast(application.getString(R.string.please_sure_new_pw))
            return
        }
        getModel().modify_pwd(oldPassword, newPassword, surePassword, object : RxHttpObserver<Any>() {
            override fun onCompleted(msg: String?, entity: Any?) {
                getView()?.showToast(msg)
                getView()?.finishActivity()
            }

            override fun onError(error: String?) {
                getView()?.showToast(error)
            }

            override fun onLoadingStart() {
                getView()?.showLoadingDialog()
            }

            override fun onLoadingFinish() {
                getView()?.dismissLoadingDialog()
            }

        })
    }
}
